package ar.com.spsolutions.splibrary.book;

import java.util.List;
import java.util.Set;

import ar.com.spsolutions.splibrary.author.Author;
import ar.com.spsolutions.splibrary.author.AuthorBuilder;
import ar.com.spsolutions.splibrary.notifiers.INotifier;

public class BookBuilder {

	private transient Book toBuild;

	private transient INotifier notifier;

	public BookBuilder(final INotifier aNotifier) {
		this.toBuild = new Book(aNotifier);
		this.notifier = aNotifier;
	}

	public BookBuilder withTitle(final String value) {
		this.getToBuild().setTitle(value);
		return this;
	}

	public BookBuilder withIsbn(final String value) {
		this.getToBuild().setIsbn(value);
		return this;
	}

	public BookBuilder withPublisher(final String value) {
		this.getToBuild().setPublisher(value);
		return this;
	}

	public BookBuilder withDescription(final String value) {
		this.getToBuild().setDescription(value);
		return this;
	}

	public BookBuilder withAvailableCopies(final Set<BookCopy> value) {
		this.getToBuild().setCopies(value);
		return this;
	}

	public BookBuilder withRentedCopies(final Set<BookCopy> value) {
		this.getToBuild().setCopies(value);
		return this;
	}

	public BookBuilder withComments(final List<BookComment> value) {
		this.getToBuild().setComments(value);
		return this;
	}

	public BookBuilder withReserve(final Reserve value) {
		this.getToBuild().setReserve(value);
		return this;
	}

	public BookBuilder withAuthor(final Author value) {
		this.getToBuild().setAuthor(value);
		return this;
	}

	public Book build() {
		final Book temp = this.getToBuild();
		this.toBuild = new Book(this.getNotifier());
		return temp;
	}

	private INotifier getNotifier() {
		return this.notifier;
	}

	private Book getToBuild() {
		return this.toBuild;
	}

	public BookBuilder withAvailableCopies(final int amount) {
		this.getToBuild().createCopies(amount);
		return this;
	}

	public static Book createInstanceForTest() {
		return new BookBuilder(null)//
				.withAuthor(AuthorBuilder.createInstanceForTest())//
				.withDescription("descripcion")//
				.withIsbn("9780553382563")//
				.build();
	}

}
